<?php

namespace App\Jobs;

use App\Models\System\OperationLog;

/**
 * 系统日志记录
 * @package App\Jobs
 */
class SysOperateLogSave extends Job
{
    protected $data;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        OperationLog::query()->create([
            'user_id' => $this->data['user_id'] ?? 0,
            'user_name' => $this->data['user_name'] ?? '',
            'opertion_name' => $this->data['opertion_name'] ?? '',
            'perm_id' => $this->data['perm_id'] ?? 0,
            'route_name' => $this->data['route_name'] ?? '',
            'ip' => $this->data['ip'] ?? '',
            'request_data' => $this->data['request_data'] ?? [],
            'add_time' => $this->data['add_time'] ?? time(),
        ]);
    }
}
